<template>
  <div>
    <div class="register">
      <div class="register-con">
        <!-- 注册页头 -->
        <div class="register-header">
          <router-link to=""
            ><img src="../../public/img/login/logo.png" alt="" class="logo-img"
          /></router-link>
          <span class="wc-word"> 欢迎注册 </span>
          <div class="has-id">
            已有账号？
            <a href="http://192.168.1.107:8080/#/login" style="color: black"
              >请登录</a
            >
          </div>
        </div>
        <!-- 注册正式部分 -->
        <div class="reg-con">
          <div class="main-on">
            <!-- 快速注册 -->
            <div class="infor-con">
              <ul class="fir-ul">
                <li style="text-align: center">
                  <label for="">用户名:</label>
                  <input type="text" v-model="uname" :disabled="!agree"/>
                  <span class="show" :class="unameClass">{{ unameMsg }}</span>
                </li>
                <li style="text-align: center">
                  <label for="">密码:</label>
                  <input type="password" v-model="pwd" :disabled="!agree"/>
                  <span class="show" :class="pwdClass">{{ pwdMsg }}</span>
                </li>
                <li style="text-align: center">
                  <label for="">电话:</label>
                  <input type="text" v-model="phone" :disabled="!agree"/>
                  <span class="show" :class="phoneClass">{{ phoneMsg }}</span>
                </li>
                <li style="text-align: center">
                  <label for="">真实姓名:</label>
                  <input type="text" v-model="user_name" :disabled="!agree"/>
                  <span class="show" :class="user_NameClass">{{
                    user_NameMsg
                  }}</span>
                </li>
                <li
                  style="text-align: center; line-height: 40px"
                  class="re-rule-li"
                >
                  <input type="checkbox" id="reagre" v-model="agree"/>
                  <label for="reagre">阅读并同意</label>
                  <a href="javascript:;">《易网聚鲜用户注册协议》</a>
                  <a href="javascript:;">《易网聚鲜服务公约》</a>
                </li>
                <li class="btn-li">
                  <button @click="register">立即注册</button>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios"
export default {
  data() {
    return {
      uname: "",
      unameMsg: "",
      unameClass: {
        success: false,
        fail: false,
      },
      pwd: "",
      pwdMsg: "",
      pwdClass: {
        success: false,
        fail: false,
      },
      phone: "",
      phoneMsg: "",
      phoneClass: {
        success: false,
        fail: false,
      },
      user_name: "",
      user_NameMsg: "",
      user_NameClass: {
        success: false,
        fail: false,
      },
      agree:false
    };
  },
  watch: {
    uname() {
      if (this.uname) {
        this.unameClass = {
          success: true,
          fail: false,
        };
        this.unameMsg = `√`;
      } else {
        this.unameClass = {
          success: false,
          fail: true,
        };
        this.unameMsg = `×`;
      }
    },
    pwd() {
      var reg = /^\d{6}$/;
      var result = reg.test(this.pwd);
      if (result === true) {
        this.pwdClass = {
          success: true,
          fail: false,
        };
        this.pwdMsg = `√`;
      } else {
        this.pwdClass = {
          success: false,
          fail: true,
        };
        this.pwdMsg = `×`;
      }
    },
    phone() {
      var reg = /^1[3-9]\d{9}$/;
      var result = reg.test(this.phone);
      if (result === true) {
        this.phoneClass = {
          success: true,
          fail: false,
        };
        this.phoneMsg = `√`;
      } else {
        this.phoneClass = {
          success: false,
          fail: true,
        };
        this.phoneMsg = `×`;
      }
    },
    user_name() {
      if (this.user_name) {
        this.user_NameClass = {
          success: true,
          fail: false,
        };
        this.user_NameMsg = `√`;
      } else {
        this.user_NameClass = {
          success: false,
          fail: true,
        };
        this.user_NameMsg = `×`;
      }
    },
  },
  methods: {
    register(){
      axios.post("/users/reg",{uname:this.uname,upwd:this.pwd,phone:this.phone,user_name:this.user_name}).then((result)=>{
        console.log(result.data);
        if(result.data.code===200){
          alert(`注册成功`);
        }else{
          alert(`注册失败`);
        }
      })
    }
  },
};
</script>
<style>
/* 注册部分页头 */
/* 页头 */
* {
  padding: 0;
  margin: 0;
}

body {
  width: 100%;
  color: #333333;
  position: relative;
  font-family: "微软雅黑", Arial;
  font-size: 12px !important;
  min-width: 1200px;
}

a {
  text-decoration: none;
}

li {
  list-style: none;
}

.register {
  width: 100%;
  padding: 30px 0;
}

.register .register-con {
  width: 1200px;
  margin: 0 auto;
}

.register .register-header {
  height: 63px;
  line-height: 63px;
  margin-bottom: 30px;
  overflow: auto;
}

.logo-img {
  background-size: 90% 90% !important;
  width: 165px;
  height: 60px;
  float: left;
  margin-top: 0 !important;
}

.register-header span {
  font-size: 28px;
  border-left: 1px solid #ddd;
  padding: 0 20px;
  float: left;
  color: #666;
  margin-left: 20px;
}

/* 字体 */
.register-header .has-id {
  float: right;
  font-size: 14px;
  color: #aaa;
}

.register-header .has-id a {
  text-decoration: none;
}

/* 注册正式部分 */
.register .register-con .reg-con ul {
  width: 600px !important;
  margin: 0 auto;
  text-align: center;
}

.register .register-con .reg-con ul li {
  margin-bottom: 30px;
  position: relative;
  margin: 0 auto;
  width: 70%;
  /* border-right: 1px solid #ddd; */
  height: 60px;
  line-height: 40px;
}

.infor-con {
  height: 286px;
}

.fir-ul li label {
  display: inline-block;
  width: 30%;
  height: 100%;
  text-align: center;
  border: 1px solid #fff;
}

.register .register-con .reg-con ul li input {
  height: 30px;
  width: 250px;
  padding-left: 10px;
  outline: none;
  font-size: 12px;
  border: 1px solid #ccc;
  color: #333;
  border-radius: 3px;
}

#reagre {
  width: 20px !important;
  position: absolute;
  left: 8px;
  top: 5px;
}

.register .register-con .reg-con ul li input[type="checkbox"] {
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.re-rule-li label {
  border-right: none !important;
  width: 20% !important;
}

.register .register-con .reg-con ul li a {
  color: #d61a39;
  font-size: 13px;
}

/* 按钮 */
.btn-li button {
  display: block;
  height: 40px;
  width: 100%;
  color: #fff;
  background: #d61a39;
  border: none;
  cursor: pointer;
  outline: none;
  font-size: 14px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}
.show {
  font-size: 12px;
  padding: 2px 6px;
}
.success {
  background-color: lightGreen;
  color: green;
  border: green 1px solid;
  border-radius: 50%;
}
.fail {
  background-color: pink;
  color: red;
  border: red 1px solid;
  border-radius: 50%;
}
</style>

